package com.hmis.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hmis.domain.Medicine;
import com.hmis.service.MedicineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@Controller
public class MedicineDAO implements InitializingBean {


    public static MedicineService medicineService;
    public static MedicineDAO medicineDAO;
    @Autowired
    private MedicineService medicine;

    public Medicine getByName(String name) {
        QueryWrapper<Medicine> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("medicine_name", name).eq("is_delete", 0);
        Medicine medicine = medicineService.getOne(queryWrapper);
        return medicine;
    }

    public List<Medicine> getLikeAll(String name) {
        QueryWrapper<Medicine> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("medicine_name", name).eq("is_delete", 0);
        List<Medicine> medicines = medicineService.list(queryWrapper);
        return medicines;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        medicineService = medicine;
        medicineDAO = this;
    }

}
